<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:p="http://primefaces.org/ui">

    <h:form id="DepartamentoListForm">

        <p:panel header="#{appBundle.ListDepartamentoTitle}">
            <p:contextMenu id="DepartamentoDataTableContextMenu" for="datalist">  
                <p:menuitem value="#{appBundle.Create}" onclick="document.getElementById('DepartamentoListForm:createButton').click();" icon="ui-icon-plus"/>
                <p:menuitem value="#{appBundle.View}" onclick="document.getElementById('DepartamentoListForm:viewButton').click();" icon="ui-icon-search"/>
                <p:menuitem value="#{appBundle.Edit}" onclick="document.getElementById('DepartamentoListForm:editButton').click();" icon="ui-icon-pencil"/>
                <p:menuitem value="#{appBundle.Delete}" onclick="document.getElementById('DepartamentoListForm:deleteButton').click();" icon="ui-icon-trash"/>
            </p:contextMenu>
            <p:dataTable id="datalist"
                         value="#{departamentoController.items}"
                         var="item"
                         rowKey="#{item.depId}"
                         paginator="true"
                         rows="10"
                         rowsPerPageTemplate="10,20,30,40,50"
                         selectionMode="single"
                         selection="#{departamentoController.selected}">

                <p:ajax event="rowSelect"   update=":DepartamentoListForm:createButton :DepartamentoListForm:viewButton :DepartamentoListForm:editButton :DepartamentoListForm:deleteButton :DepartamentoListForm:DepartamentoDataTableContextMenu"/>
                <p:ajax event="rowUnselect" update=":DepartamentoListForm:createButton :DepartamentoListForm:viewButton :DepartamentoListForm:editButton :DepartamentoListForm:deleteButton :DepartamentoListForm:DepartamentoDataTableContextMenu"/>
                <p:ajax event="rowDblselect" onsuccess="document.getElementById('DepartamentoListForm:viewButton').click();"/>

                <p:column sortBy="#{item.depId}" filterBy="#{item.depId}">
                    <f:facet name="header">
                        <h:outputText value="#{appBundle.ListDepartamentoTitle_depId}"/>
                    </f:facet>
                    <h:outputText value="#{item.depId}"/>
                </p:column>


                <p:column sortBy="#{item.repaCodigo2}" filterBy="#{item.repaCodigo2}">
                    <f:facet name="header">
                        <h:outputText value="#{appBundle.ListDepartamentoTitle_repaCodigo2}"/>
                    </f:facet>
                    <h:outputText value="#{repartoController.findObj(item.repaCodigo2).repaDenominacion}"/>
                </p:column>


                <p:column sortBy="#{item.depSiglas}" filterBy="#{item.depSiglas}">
                    <f:facet name="header">
                        <h:outputText value="#{appBundle.ListDepartamentoTitle_depSiglas}"/>
                    </f:facet>
                    <h:outputText value="#{item.depSiglas}"/>
                </p:column>


                <p:column sortBy="#{item.depDenominacion}" filterBy="#{item.depDenominacion}">
                    <f:facet name="header">
                        <h:outputText value="#{appBundle.ListDepartamentoTitle_depDenominacion}"/>
                    </f:facet>
                    <h:outputText value="#{item.depDenominacion}"/>
                </p:column>


                <p:column sortBy="#{item.depActi}" filterBy="#{item.depActi}">
                    <f:facet name="header">
                        <h:outputText value="#{appBundle.ListDepartamentoTitle_depActi}"/>
                    </f:facet>
                    <h:selectBooleanCheckbox id="depActi" value="#{item.depActi}" title="#{appBundle.EditDepartamentoTitle_depActi}"  disabled="true"/>
                </p:column>


            </p:dataTable>

            <p:commandButton id="createButton"                             icon="ui-icon-plus"   value="#{appBundle.Create}" actionListener="#{departamentoController.prepareCreate}" update=":DepartamentoCreateForm" oncomplete="DepartamentoCreateDialog.show()"/>
            <p:commandButton id="viewButton"   style="visibility: hidden;" icon="ui-icon-search" value="#{appBundle.View}" update=":DepartamentoViewForm" oncomplete="DepartamentoViewDialog.show()" disabled="#{empty departamentoController.selected}"/>
            <p:commandButton id="editButton"   style="visibility: hidden;" icon="ui-icon-pencil" value="#{appBundle.Edit}" update=":DepartamentoEditForm" oncomplete="DepartamentoEditDialog.show()" disabled="#{empty departamentoController.selected}"/>
            <p:commandButton id="deleteButton" style="visibility: hidden;" icon="ui-icon-trash"  value="#{appBundle.Delete}" actionListener="#{departamentoController.delete}" update=":growl,datalist" disabled="#{empty departamentoController.selected}">
                <p:confirm header="#{appBundle.ConfirmationHeader}" message="#{appBundle.ConfirmDeleteMessage}" icon="ui-icon-alert"/>
            </p:commandButton>

        </p:panel>
        <ui:include src="/confirmation.xhtml"/>
    </h:form>

</ui:composition>